package com.ycfmedical.bed.ui;


import com.ycfmedical.bed.Constants;
import com.ycfmedical.bed.R;
import com.ycfmedical.bed.base.BaseDetailActivity;
import com.ycfmedical.bed.model.HealthResults.ResultBean;
import com.ycfmedical.bed.provider.Card;
import com.ycfmedical.bed.provider.Category;
import com.ycfmedical.bed.provider.Line;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import cn.droidlover.xdroidmvp.imageloader.ILFactory;
import cn.droidlover.xdroidmvp.kit.Kits;
import cn.droidlover.xdroidmvp.router.Router;
import me.drakeet.multitype.Items;

/**
 * Created by Egoist on 2017/2/20.
 */

public class HealthDetailActivity extends BaseDetailActivity {

    @NonNull
    ResultBean data;

    @Override
    public void initData(Bundle savedInstanceState) {
        data  = (ResultBean)getIntent().getParcelableExtra(Constants.HEALTHNEWS);
        super.initData(savedInstanceState);
    }

    @Override
    public void setTitle(CharSequence title) {
        super.setTitle(title);
    }

    @Override
    protected void onCreateHeader(ImageView icon, TextView title, TextView time) {

        setTitle(data.getTitle());//设置toolbar标题栏
        ILFactory.getLoader().loadNet(icon,data.getImg(),null);
        title.setText(data.getTitle());//设置约束布局中的Title
        time.setText(Kits.Date.getYmdDot(data.getTime()));
    }

    @Override
    protected void onItemsCreated(@NonNull Items items) {
        items.add(new Category("文章内容"));
        items.add(new Card(data.getDescription(), "分享"));
        items.add(new Line());
    }

    //点击分享后调用
    @Override protected void onActionClick(View action) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
        intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_content));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(Intent.createChooser(intent, getTitle()));
    }

    @Override
    public Object newP() {
        return null;
    }

    public static void launch(Activity activity,Bundle bundle)
    {
        Router.newIntent(activity).data(bundle).to(HealthDetailActivity.class).launch();
    }
}
